package com.yzh.chatgpt.session.impl;

import com.yzh.chatgpt.IOpenAiApi;
import com.yzh.chatgpt.model.ChatCompletionRequest;
import com.yzh.chatgpt.model.ChatCompletionResponse;
import com.yzh.chatgpt.session.ChatSession;

public class DefaultChatSession implements ChatSession {
    private IOpenAiApi openApi;

    public DefaultChatSession(IOpenAiApi openApi) {
        this.openApi = openApi;
    }

    @Override
    public ChatCompletionResponse completions(ChatCompletionRequest chatCompletionRequest) {
        //Retrofit2发起请求同步获取响应，blockingGet()方法阻塞当前线程，直到获取结果为止。
        return this.openApi.completions(chatCompletionRequest).blockingGet();
    }
}
